package y24.m4;

class Auto{
    private double speed;
    private boolean status;

    public double getSpeed() {
        return speed;
    }

    public boolean isStatus() {
        return status;
    }

    public void start(){
        this.status = true;
        this.speed = 60;
        System.out.println("已启动");
    }
    public boolean speedUp(int speed){
        if (status){
            this.speed += speed;
            System.out.println("加速成功，现速度为：" + this.speed);
            return true;
        }else {
            System.out.println("没有启动无法加速");
            return false;
        }
    }
    public void stop(){
        this.status = false;
        System.out.println("已停止");
    }
}
class Bus extends Auto{
    private static int PASSENGER = 0;
    public boolean getOn(int passenger){
        if (super.isStatus()){
            System.out.println("公交没有停止不能上车");
            return false;
        }
        PASSENGER += passenger;
        System.out.println("有" + passenger + "名乘客上车，现在车上有" + PASSENGER + "名乘客");
        return true;
    }
    public boolean getOff(int passenger){
        if (super.isStatus()){
            System.out.println("公交没有停止不能下车");
            return false;
        }
        if (PASSENGER == 0){
            System.out.println("车上没有乘客");
            return false;
        }
        if (passenger <= PASSENGER){
            PASSENGER -= passenger;
            if (PASSENGER == 0) {
                System.out.println("所有乘客已下车");
            }else {
                System.out.println("有" + passenger + "名乘客下车，现在车上有" + PASSENGER + "名乘客");
            }
            return true;
        }else {
            System.out.println("车上没有那么多的乘客需要下车");
            return false;
        }

    }
}
public class Test12 {
    public static void main(String[] args) {
        Bus bus = new Bus();
        bus.start();
        System.out.println("公交的初始速度: " + bus.getSpeed());
        bus.speedUp(10);
        bus.getOn(10);
        bus.getOff(10);
        bus.stop();
        bus.getOff(10);
        bus.getOn(10);
        bus.getOff(5);
        bus.getOff(6);
        bus.getOff(5);
    }
}
